package com.xiyuan.controller.memoManage;

import com.xiyuan.pojo.result.PageBean;
import com.xiyuan.pojo.result.Result;
import com.xiyuan.pojo.entity.MemoEvent;
import com.xiyuan.service.MemoEventService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/article")
public class MemoEventController {

    @Autowired
    private MemoEventService memoEventService;

    /**
     * 新增事件
     * @param memoEvent
     * @return
     */
    @PostMapping
    public Result insert(@RequestBody MemoEvent memoEvent) {
        memoEventService.insert(memoEvent);
        return Result.success();
    }

    /**
     * 事件列表
     * @param memoEvent
     * @return
     */
    @GetMapping
    public Result<PageBean<MemoEvent>> list(MemoEvent memoEvent){
        return Result.success(memoEventService.list(memoEvent));
    }

    /**
     * 事件详情
     * @param id
     * @return
     */
    @GetMapping("/detail")
    public Result<MemoEvent> getById(Integer id){
        return Result.success(memoEventService.getById(id));
    }

    @PutMapping
    public Result update(@RequestBody MemoEvent memoEvent) {
        memoEventService.update(memoEvent);
        return Result.success();
    }

    /**
     * 删除事件
     * @param id
     * @return
     */
    @DeleteMapping
    public Result delete(@Validated Integer id) {
        memoEventService.delete(id);
        return Result.success();
    }
}
